package Demo2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-05-29
 * Time: 17:16
 */
public class Test {
    public static void main3(String[] args)
            throws CloneNotSupportedException{
        //深拷贝
        Person person = new Person("wangwu",4);
        person.money.m = 20;
        Person person1 = (Person) person.clone();
        Money money = (Money) person.money.clone();
        System.out.println(person.money.m);
        System.out.println(person1.money.m);
        System.out.println("------");
        person.money.m = 10;
        person1.money.m = 5;
        System.out.println(person.money.m);
        System.out.println(person1.money.m);

    }
    public static void main2(String[] args)
            throws CloneNotSupportedException{
        //浅拷贝
        Person person1 = new Person("zhangsan",2);
        person1.money.m = 10;
        Person person2 = (Person) person1.clone();
        System.out.println(person1.money.m);
        System.out.println(person2.money.m);
        System.out.println("------");
        person2.money.m = 20;
        System.out.println(person1.money.m);
        System.out.println(person2.money.m);
    }
    public static void main1(String[] args)
            throws CloneNotSupportedException{
        Person person1 = new Person("zhangsan",2);
        Person person2 = (Person) person1.clone();
        System.out.println(person2.toString());

        person1.money.m = 10;
        System.out.println(person1.money.m);
        System.out.println(person2.money.m);
        person2.money.m = 20;
        System.out.println(person1.money.m);
        System.out.println(person2.money.m);

        Person person = new Person("wangwu",4);
        Money money = (Money) person1.money.clone();
    }
}
